Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitfinex: Fix WS trade processing #1754

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gbjk
Copy link
Collaborator

@gbjk gbjk commented Dec 18, 2024

  • Bitfinex
    • Fixes exchange Bitfinex websocket error - unhandled WS trade update event:
    • Add tests for TestWSAllTrades
    • Add handling for public marginFunding trades
    • Fix idiosyncratic naming using TestWs instead of TestWS
    • Fix naming for wsTradeUpdated ( was wsTradeExecutionUpdate )
    • Fix trades not going to DataHandler unless SaveTrade was enabled
    • Enable tradeFeed for tests
  • Linter
    • Disables shadow checks for err and ctx. Advocated this before, but had my fill of stylecheck (correctly, IMO) fighting with shadow over this rule. This isn't strictly necessary, but it's nearly christmas again.

Fixes #1746
Progresses #1323 with a prototype

Type of change

  • Bug fix (non-breaking change which fixes an issue)

* Add handling for funding trades

Fixes thrasher-corp#1746
@gbjk gbjk added bug review me This pull request is ready for review labels Dec 18, 2024
@gbjk gbjk self-assigned this Dec 18, 2024
@gbjk gbjk force-pushed the bugfix/bitfinex_ws_trade branch from 89cbb66 to 0dd865c Compare December 18, 2024 07:29
It's been a year, and I'm still getting caught out by govet demanding I
don't shadow a var I was deliberately shadowing.
Made worse by an increase in clashes with stylecheck when they both want
opposite things on the same line.
@gbjk gbjk force-pushed the bugfix/bitfinex_ws_trade branch from 0dd865c to cb416cc Compare December 19, 2024 01:52
Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice stuff, not much from me.

// TestWsCancelOrder dials websocket, sends modify request.
func TestWsUpdateOrder(t *testing.T) {
// TestWSCancelOrder dials websocket, sends modify request.
func TestWSUpdateOrder(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestWSUpdateOrder(t *testing.T) {
func TestWSModifyOrder(t *testing.T) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DriveBy hit a few other naming fails whilst there.

Fixed gbjk@c7db5d8a2

Comment on lines +36 to +38
var (
errParsingWSField = errors.New("error parsing WS field")
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var (
errParsingWSField = errors.New("error parsing WS field")
)
var errParsingWSField = errors.New("error parsing WS field")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so convinced, oddly, since it feels like this is a block of error vars, that happens to only contain one.
I want devs to add to it, essentially.

Did linter or editor highlight this?

return errors.New("unable to type assert trade amount")
if t.Amount < 0 {
t.Side = order.Sell
t.Amount *= -1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Amount *= -1
t.Amount = math.Abs(t.Amount)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !ok {
return errors.New("unable to type assert trade price")
t := &wsTrade{}
if err := json.Unmarshal(v, &[]any{&t.ID, &t.Timestamp, &t.Amount, &t.Price, &t.Period}); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: can define an UnmarshalJSON method with this and use the type wsTrade here and below in handleWSPublicTradeUpdate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, that's really cute, thank you 🙏
I've put it in _types since it's a micro-method and there's nowhere moar organic to put it, other than maybe in _websocket next to the funcs that'll use it.

Fixed gbjk@4d3a7e0a4

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 55.69620% with 35 lines in your changes missing coverage. Please review.

Project coverage is 37.40%. Comparing base (105591b) to head (4d3a7e0).
Report is 28 commits behind head on master.

Files with missing lines Patch % Lines
exchanges/bitfinex/bitfinex_websocket.go 53.33% 26 Missing and 9 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1754      +/-   ##
==========================================
+ Coverage   37.13%   37.40%   +0.26%     
==========================================
  Files         414      415       +1     
  Lines      180198   178586    -1612     
==========================================
- Hits        66925    66807     -118     
+ Misses     105413   103990    -1423     
+ Partials     7860     7789      -71     
Files with missing lines Coverage Δ
exchanges/bitfinex/bitfinex_types.go 100.00% <100.00%> (ø)
exchanges/btse/btse_wrapper.go 43.77% <100.00%> (ø)
exchanges/subscription/template.go 97.70% <100.00%> (-2.30%) ⬇️
exchanges/bitfinex/bitfinex_websocket.go 36.00% <53.33%> (+3.20%) ⬆️

... and 50 files with indirect coverage changes

@gbjk gbjk requested a review from shazbert December 27, 2024 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug review me This pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bitfinex: Fix WS Trade stream erroring
2 participants